<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>   
    <base href="<%=basePath%>"/>
    <title>广元电业局低质易耗品管理平台</title>
	<link rel="stylesheet" rev="stylesheet" href="css/style.css" type="text/css" media="all" />
	<!-- DTree -->
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.4.2.min.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/jquery.blockUI.js"></script> 
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/dtree.js"></script>
	
	<!-- DWR -->
	<script type="text/javascript" src="${pageContext.request.contextPath}/dwr/engine.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/dwr/util.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/dwr/interface/categoryManager.js"></script>
</head>

<body class="ContentBody" onload="showFirstLevel();">
<form action="updateCategory.action" method="post">
<div class="MainDiv">
	<table width="99%" border="0" cellpadding="0" cellspacing="0" class="CContent">
		  <tr>
		      <th class="tablestyle_title" >资产类型信息录入</th>
		  </tr>
		  <tr>
		    <td class="CPanel">
				<table border="0" cellpadding="0" cellspacing="0" style="width:100%">
				<tr>		
				   <td width="100%">
					  <fieldset style="height:100%;">
						<legend>资产类型信息</legend>	
							<input type="hidden" value="<s:property value='category.catid' />" id="assetCategoryId" name="category.catid"/>
							<input type="hidden" id="originalCategoryId" name="originalCategoryId" />	      
							<table border="0" cellpadding="2" cellspacing="1" style="width:100%">
								<tr>									  
								  <td align="right">资产类型名称:</td>
								     <td>
								     	<input type="text" value="<s:property value='category.catname' />" name="category.catname"/>
			                            <span style="color: red">*</span>
			                        </td>
								   <td align="right">资产类型简称:</td>
								   <td ><input value="<s:property value='category.catsimplename' />" name="category.catsimplename" type="text" class="text" style="width:154px"/></td>                      			     
								 </tr>		    
								 <tr>
								   <td align="right">一级分类:</td>
								   <td>
								   	<select class="text" name="firstLevel" id="firstLevel" style="width:154px" onclick="showSecondLevel();setAssetCategoryId();">
								   		<option value="empty">不填为一级分类</option>
								   	</select>
								   </td>  	             
								   <td align="right">资产类型别名:</td>
								   <td><input class="text" value="<s:property value='category.catalias' />" name="category.catalias" style="width:154px" /></td>  
								 </tr>
								  <tr> 
								    <td align="right">二级分类:</td>
								    <td>
								    	<select class="text" name="secondLevel" id="secondLevel" style="width:154px" onclick="setAssetCategoryId();" >
											<option value="empty">不填为二级分类</option>
								   		</select>
								   	</td>
								   	<td align="right">资产规格:</td>
								    <td><input class="text" value="<s:property value='category.catnorms' />" name="category.catnorms" style="width:154px"/></td>  
								  </tr> 					  		  
								  <tr> 
								    <td align="right">计量单位:</td>
								    <td><input class="text" value="<s:property value='category.catunit' />" name="category.catunit" style="width:154px" /></td>
								 	<td align="right">最低库存数量:</td>
								    <td><input class="text" value="<s:property value='category.catlowstock' />" name="category.catlowstock" style="width:154px" /></td>				    
								  </tr>       
								  <tr>	
								   	<td align="right">最高库存数量:</td>
								    <td><input class="text" value="<s:property value='category.cathighstock' />" name="category.cathighstock" style="width:154px" /></td>	    				   
								  </tr>
						</table>
							  <br />
						</fieldset>
					</td>
				</tr>
				</table>	
		 	</td>
		</tr>			
		<tr>
			<td colspan="2" align="center" height="50px">
			<input type="submit" name="Submit" value="保存" class="button" onclick="submitButton()"/>　
			<input type="button" name="Submit2" value="返回" class="button" onclick="window.history.go(-1);"/>
			</td>
		</tr> 
	</table>
</div>
</form>

	<script type="text/javascript">
		function submitButton(){
			var firstLevelValue = document.getElementById("firstLevel").value;
			var secondLevelValue = document.getElementById("secondLevel").value;
			if(firstLevelValue != "empty" && secondLevelValue != "empty"){
				$('#originalCategoryId').val($('#assetCategoryId').val());
				$('#assetCategoryId').val(secondLevelValue);
			}
		}
	
		function showFirstLevel(){
			var selectObject = document.getElementById("firstLevel");
			categoryManager.findAllCategory(function(categoryList){
			selectObject.options.length = 0;
			var empty = new Option('不填为一级分类','empty');
			selectObject.options.add(empty);
				for(var i=0; i<categoryList.length; i++){
					var size = categoryList[i].catid.length;
					if(size == 3){
						var object = new Option(categoryList[i].catname,categoryList[i].catid);
						selectObject.options.add(object);
					}//end if
				}//end if
			});// end dwr
		}
		
		function showSecondLevel(){
			var selectObject = document.getElementById("secondLevel");
			var firstLevelId = $('#firstLevel').val();
			categoryManager.findAllCategory(function(categoryList){
			selectObject.options.length = 0;
			var empty = new Option('不填为二级分类','empty');
			selectObject.options.add(empty);
				for(var i=0; i<categoryList.length; i++){
					var size = categoryList[i].catid.length;
					if(size == 6){//判断是否是一级分类下的二级分类
						if(firstLevelId == categoryList[i].catid.substr(0,3)){		
							var object = new Option(categoryList[i].catname,categoryList[i].catid);
							selectObject.options.add(object);
						}
					}
				}//end for
			});// end dwr
		}
	</script>
</body>
</html>

